﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace DnsCatcher.Service
{
    public class Logger
    {
        private static string EVT_SOURCE = "DNS Reporting Services";
        private static string EVT_LOG = "Application";

        public static void LogException(Exception ex)
        {
            if (!EventLog.SourceExists(EVT_SOURCE))
                EventLog.CreateEventSource(EVT_SOURCE, EVT_LOG);

            EventLog.WriteEntry(EVT_SOURCE, ex.Message, EventLogEntryType.Error, 
                0, 0, Encoding.ASCII.GetBytes(ex.ToString()));
        }

        public static void LogMessage(string message, params object[] args)
        {
            LogMessage(String.Format(message, args));
        }

        public static void LogMessage(string message)
        {
            if (!EventLog.SourceExists(EVT_SOURCE))
                EventLog.CreateEventSource(EVT_SOURCE, EVT_LOG);

            EventLog.WriteEntry(EVT_SOURCE, message, EventLogEntryType.Information);
        }
    }
}
